package com.config;

import com.volcengine.ark.runtime.service.ArkService;
import lombok.RequiredArgsConstructor;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
@RequiredArgsConstructor
public class ArkServiceConfig {

    @Value("${volcengine.api-key}")
    private String apiKey;

    @Value("${volcengine.base-url}")
    private String baseUrl;

    @Bean
    public ArkService arkService() {
        // 配置连接池和调度器
        ConnectionPool connectionPool = new ConnectionPool(5, 10, TimeUnit.SECONDS);
        Dispatcher dispatcher = new Dispatcher();
        dispatcher.setMaxRequests(20);
        dispatcher.setMaxRequestsPerHost(5);

        return ArkService.builder()
                .dispatcher(dispatcher)
                .connectionPool(connectionPool)
                .baseUrl(baseUrl)
                .apiKey(apiKey)
                .build();
    }
}